package com.xmut.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.xmut.mall.product.annotation.CheckJwt;
import com.xmut.mall.product.utils.RespBean;
import com.xmut.mall.product.vo.addToGroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.product.entity.AttrAttrgroupRelationEntity;
import com.xmut.mall.product.service.AttrAttrgroupRelationService;
import com.xmut.mall.product.utils.PageUtils;
import com.xmut.mall.product.utils.R;



/**
 * 属性&属性分组关联
 *
 * @author 1912120131suntingxing
 * @email 1192081604@qq.com
 * @date 2022-07-14 00:45:34
 */
@RestController
@RequestMapping("product/attrattrgrouprelation")
public class AttrAttrgroupRelationController {
    @Autowired
    private AttrAttrgroupRelationService attrAttrgroupRelationService;

    /**
     * 根据表id移除关联关系
     * @param id
     * @return
     */
    @CheckJwt
    @DeleteMapping("/removeRelation/{id}")
    public RespBean removeRelation(@PathVariable Long id){
        return attrAttrgroupRelationService.removeRelation(id);
    }



    /**
     * 添加分组的关联属性
     * @param vo
     * @return
     */
    @CheckJwt
    @PostMapping("addToGroup")
    public RespBean addToGroup(@RequestBody addToGroupVo vo){
        return attrAttrgroupRelationService.addToGroup(vo);
    }

    /**
     * 根据当前分组的id获取未被当前分组所关联的属性
     * @param id
     * @return
     */
    @CheckJwt
    @GetMapping("/getNoRelationAttrByGroupId/{id}")
    public RespBean getNoRelationAttrByGroupId(@PathVariable Long id){
        return attrAttrgroupRelationService.getNoRelationAttrByGroupId(id);
    }


    /**
     * 根据分组的id获取当前分组的属性关联信息
     * @param groupId
     * @return
     */
    @CheckJwt
    @GetMapping("/getAttrGroupRelationByGroupId/{groupId}")
    public RespBean getAttrGroupRelationByGroupId(@PathVariable Long groupId){
        return attrAttrgroupRelationService.getAttrGroupRelationByGroupId(groupId);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAttrgroupRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.save(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
